package ccc

import (
	"github.com/hyperledger/fabric-gateway/pkg/client"
)

type FabNetworkClient struct {
	OrgName string
	MSPID   string
	//CryptoPath   string
	CertPath     string
	KeyPath      string
	TLSCertPath  string
	PeerEndpoint string
	GatewayPeer  string
	Gateway      client.Gateway
}

//func New(OrgName, MSPID, CertPath, KeyPath, TLSCertPath, PeerEndpoint, GatewayPeer string) (*FabNetworkClient, error) {
//	fabNetworkClient := FabNetworkClient{
//		OrgName:      OrgName,
//		MSPID:        MSPID,
//		CertPath:     CertPath,
//		KeyPath:      KeyPath,
//		TLSCertPath:  TLSCertPath,
//		PeerEndpoint: PeerEndpoint,
//		GatewayPeer:  GatewayPeer,
//	}
//	return Initialize(fabNetworkClient)
//}

func New(CryptoPath,
	OrgName,
	MSPID,
	CertPath,
	KeyPath,
	TLSCertPath,
	PeerEndpoint,
	GatewayPeer string) (*FabNetworkClient, error) {
	fabNetworkClient := new(FabNetworkClient)
	fabNetworkClient = fabNetworkClient.withOrgName(OrgName).withMSPID(MSPID).withCertPath("", CertPath).withKeyPath("", KeyPath).withTLSCertPath("", TLSCertPath).withPeerEndpoint(PeerEndpoint).withGatewayPeer(GatewayPeer)

	return initialize(fabNetworkClient)
}

func (fabNetworkClient *FabNetworkClient) withOrgName(OrgName string) *FabNetworkClient {
	fabNetworkClient.OrgName = OrgName
	return fabNetworkClient
}

func (fabNetworkClient *FabNetworkClient) withMSPID(MSPID string) *FabNetworkClient {
	fabNetworkClient.MSPID = MSPID
	return fabNetworkClient
}

func (fabNetworkClient *FabNetworkClient) withCertPath(CryptoPath, CertPath string) *FabNetworkClient {
	fabNetworkClient.CertPath = CryptoPath + CertPath
	return fabNetworkClient
}

func (fabNetworkClient *FabNetworkClient) withKeyPath(CryptoPath, KeyPath string) *FabNetworkClient {
	fabNetworkClient.KeyPath = CryptoPath + KeyPath
	return fabNetworkClient
}

func (fabNetworkClient *FabNetworkClient) withTLSCertPath(CryptoPath, TLSCertPath string) *FabNetworkClient {
	fabNetworkClient.TLSCertPath = CryptoPath + TLSCertPath
	return fabNetworkClient
}

func (fabNetworkClient *FabNetworkClient) withPeerEndpoint(PeerEndpoint string) *FabNetworkClient {
	fabNetworkClient.PeerEndpoint = PeerEndpoint
	return fabNetworkClient
}

func (fabNetworkClient *FabNetworkClient) withGatewayPeer(GatewayPeer string) *FabNetworkClient {
	fabNetworkClient.GatewayPeer = GatewayPeer
	return fabNetworkClient
}
